#include <iostream>
#include <stack>
#include <cstring>
using namespace std;

typedef long long LL;

const int N = 1e5 + 10;
LL a[N], n, ret1[N], ret2[N];
LL ret[N];

int main()
{
	while(cin >> n, n)
	{
		memset(ret, 0, sizeof ret);
		memset(ret1, 0, sizeof ret1);
		memset(ret2, 0, sizeof ret2);
		for(int i = 1; i <= n; i++) cin >> a[i];
		stack<int> st;
		for(int i = 0; i <= n + 1; i++)
		{
			while(st.size() && a[st.top()] >= a[i]) st.pop();
			if(st.size()) ret1[i] = st.top();
			else ret1[i] = 0;
			st.push(i);
		}	
		while(st.size()) st.pop();
		for(int i = n + 1; i >= 0; i--)
		{
			while(st.size() && a[st.top()] >= a[i]) st.pop();
			if(st.size()) ret2[i] = st.top();
			else ret2[i] = n + 1;
			st.push(i);
		}
		
//		for(int i = 1; i <= n; i++) cout << ret2[i] << " ";
//		cout << endl;
		
		LL ans = 0;
		for(int i = 1; i <= n; i++)
		{
			int x = ret1[i], y = ret2[i];
//			if(y == 0) y = n + 1;
			ans = max(ans, a[i] * (y - x - 1));
		}	
		
		cout << ans << endl;
		
	}
	return 0;
}
